<?php

class HomeModel extends Model {
	function getLastIdUser(){
		$result = $this->query('SELECT user.idUser FROM user ORDER BY user.idUser DESC LIMIT 1');
		return $result;
	}
	function validateUserandPassword($field){
		$result = $this->query('SELECT User.iduser, User.Username FROM User WHERE user.username = ' ."'" .$field['username'] ."' AND user.password = " ."'" .$field['password'] ."'" );
		return $result;
	}
	function insertUserProfile($field){
		$result = 1;
		if(mkdir("workdirserver/".$field['username'],0777)==true){
			if(mkdir("workdirserver/".$field['username']."/1",0777)==true){
				$result = $this->query('INSERT INTO user (name,email,username,password,indexnewestdir) VALUES(' ."'" .$field['name'] ."','" .$field['email']  ."','" .$field['username'] ."','" .$field['password'] ."',1)");
			}
			
		}
		return count($result);
	}
	function checkusername($username){
		$result = $this->query('SELECT User.iduser FROM User WHERE user.username = ' ."'" .$username ."'") ;
		return $result;
	}
}
